package com.hqhy.like.stock.dao.persist.repository.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hqhy.like.common.pojo.vo.PageData;
import com.hqhy.like.common.util.PageInfoToPageDataConverter;
import com.hqhy.like.stock.dao.persist.mapper.TotalMapper;
import com.hqhy.like.stock.dao.persist.repository.ITotalRepository;
import com.hqhy.like.stock.pojo.dto.TotalUpdateDTO;
import com.hqhy.like.stock.pojo.entity.Total;
import com.hqhy.like.stock.pojo.vo.TotalListItemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class TotalRepositoryImpl implements ITotalRepository {

    @Autowired
    private TotalMapper totalMapper;

    @Override
    public int insert(Total total) {
        return totalMapper.insert(total);
    }

    @Override
    public int deleteById(Long id) {
        return totalMapper.deleteById(id);
    }

    @Override
    public int deleteByNameAndUnit(String name, String unit) {
        return totalMapper.deleteByNameAndUnit(name, unit);
    }

    @Override
    public int updateById(Total total) {
        return totalMapper.updateById(total);
    }

    @Override
    public int updateByNameAndUnit(String name, String unit, Integer number) {
        return totalMapper.updateByNameAndUnit(name, unit, number);
    }


    @Override
    public PageData<TotalListItemVO> list(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<TotalListItemVO> list = totalMapper.list();
        PageInfo<TotalListItemVO> pageInfo = new PageInfo<>(list);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }

    @Override
    public TotalUpdateDTO selectTotalById(Long id) {
        return totalMapper.selecTotalById(id);
    }

    @Override
    public TotalUpdateDTO selectTotalByNameAndUnit(String name, String unit) {
        return totalMapper.selectTotalByNameAndUnit(name, unit);
    }


}
